home *** CD-ROM | disk | FTP | other *** search
- // NewHelp
- // version 1.0.1
- // by Ken Long <kenlong@netcom.com>
- // updated for CW7 on 951215
-
- typedef struct {
- short textRsrc, stylRsrc;
- }TopicSet;
-
- typedef struct {
- short numTopics;
- TopicSet topicSets [1];
- } HelpList, *HelpListPtr, **HelpListHdl;
-
- DialogPtr myDialog;
- HelpListHdl myHelpListH;
- ListHandle theList;
- short pagesize, numTopics;
- Handle textRes, numTopicsH;
- ControlHandle sBar;
- TEHandle theText;
- Boolean finished;
-
-
- pascal void ScrAction(ControlHandle control, short controlPart)
- {
- short step, oldValue;
-
- if (controlPart == 0)
- return;
-
- switch( controlPart )
- {
- case inUpButton:
- step = -10;
- break;
-
- case inDownButton:
- step = 10;
- break;
-
- case inPageUp:
- step = -pagesize;
- break;
-
- case inPageDown:
- step = pagesize;
- break;
- }
- if( controlPart != 0 )
- {
- oldValue = GetCtlValue(control);
- SetCtlValue(control, oldValue + step);
- TEScroll(0, oldValue - GetCtlValue(control), theText);
- }
- }
-
- void WindowScroll(Point thePt, WindowPtr theWindow)
- {
- ControlHandle control;
- short part, oldValue;
-
- GlobalToLocal(&thePt);
- switch( FindControl(thePt, theWindow, &control) )
- {
- case inUpButton:
- case inPageUp:
- case inDownButton:
- case inPageDown:
- part = TrackControl(control, thePt, (ControlActionUPP) ScrAction);
- break;
-
- case inThumb:
- {
- oldValue = (**theText).viewRect.top - (**theText).destRect.top;
- if( TrackControl(control, thePt, 0L) != 0 )
- TEScroll(0, oldValue - GetCtlValue(control), theText);
- }
- }
- }
-
- void LoadText(short item)
- {
- short inactive = 255;
-
- short max, textNum, stylNum;
- Handle textRes, stylRes;
-
- TEDeactivate(theText);
- TESetSelect(0, 32767, theText);
- TEDelete(theText);
-
- (**theText).destRect = (**theText).viewRect;
-
- textNum = (*myHelpListH)->topicSets[item].textRsrc;
- stylNum = (*myHelpListH)->topicSets[item].stylRsrc;
-
- if( (textNum != 0) & (stylNum != 0) )
- {
- textRes = GetResource('TEXT', textNum);
- stylRes = GetResource('styl', stylNum);
- HLock(textRes);
- HLock(stylRes);
- TEStylInsert(*textRes, SizeResource(textRes), (StScrpHandle) stylRes, theText);
- HUnlock(stylRes);
- HUnlock(textRes);
- }
- max = TEGetHeight((**theText).nLines, 0, theText) - pagesize;
- if( max > 0 )
- HiliteControl(sBar, activeFlag);
- else
- HiliteControl(sBar, inactive);
-
- SetCtlValue(sBar, 0);
- SetCtlMax(sBar, max);
- TEActivate(theText);
- }
-
- Boolean MyFilter(DialogPtr theDialog, EventRecord *theEvent,
- short *itemHit)
- {
- short iType, part;
- Rect iBox;
- Handle iHdl;
- Point thePt;
- ControlHandle control;
- Boolean ignore;
- Cell newCell;
- long ticks;
-
- if (theEvent->what == mouseDown)
- {
- thePt = theEvent->where;
- GlobalToLocal(&thePt);
- part = FindControl(thePt, myDialog, &control);
-
- if (control == sBar)
- WindowScroll(theEvent->where, myDialog);
- else
- if ( control == (**theList).vScroll )
- ignore = LClick(thePt, theEvent->modifiers, theList);
- else
- if (PtInRect(thePt, &(**theList).rView))
- {
- ignore = LClick(thePt, theEvent->modifiers, theList);
- SetPt(&newCell, 0, 0);
- ignore = LGetSelect(true, &newCell, theList);
- LoadText(newCell.v);
- }
- }
-
- if (theEvent->what == updateEvt)
- {
- TEUpdate(&(**theText).viewRect, theText);
- LUpdate(myDialog->visRgn, theList);
- }
- }
-
- pascal void MyItemProc(WindowPtr theDlg, short itemHit )
- {
- Rect iRect;
- Handle iHndl;
- short iType;
-
- GetDItem (theDlg, 1, &iType, &iHndl, &iRect ); // item #1
- PenSize( 3,3 );
- InsetRect( &iRect, -4,-4);
- FrameRoundRect( &iRect, 16,16 );
- }
-
- void CreateList()
- {
- short i, iType;
- Str255 topicStr;
- Rect iRect, dataBounds;
- Cell cSize, theCell;
- Handle iHandle;
-
- GetDItem(myDialog, 3, &iType, &iHandle, &iRect);
- FrameRect(&iRect);
- InsetRect(&iRect, 1, 1);
- SetPt(&cSize, iRect.right - iRect.left, 12);
- SetRect(&dataBounds, 0, 0, 1, numTopics);
- theList = LNew(&iRect, &dataBounds, cSize, 0, myDialog, false, false, false, true);
-
- //o DrawIt, hasGrow, hScroll, vScroll.
- for (i = 1; i <= numTopics; i++)
- {
- GetIndString(topicStr, 256, i);
- SetPt(&theCell, 0, i - 1);
- LSetCell((Ptr) &topicStr + 1, *topicStr, theCell, theList);
- }
- (**theList).selFlags = lOnlyOne;
- SetPt(&theCell, 0, 0);
- LSetSelect(TRUE, theCell, theList);
-
- //o Set drawing to True now that list is built.
- LDoDraw(TRUE, theList);
- }
-
- void Help(short strRsrcNum, short hlpRsrcNum)
- {
- GrafPtr savePort;
- EventRecord theEvent;
- Rect iBox, tBox;
- short iType, itemHit, thePart;
- Handle iHdl;
- Point mLoc;
-
- GetPort(&savePort);
- myDialog = GetNewDialog(1001, 0L, (WindowPtr)-1L);
- SetPort(myDialog);
-
- GetDialogItem( myDialog, 5, &iType, &iHdl, &iBox );
- SetDialogItem( myDialog, 5, iType, (Handle) MyItemProc, &iBox );
- ShowWindow(myDialog);
-
- TextFont(monaco);
- TextSize(9);
-
- numTopics = **(short **)GetResource('STR#', strRsrcNum);
- myHelpListH = (HelpListHdl) (GetResource('HLP#', hlpRsrcNum));
- HLock((Handle) (myHelpListH));
-
- CreateList ();
- GetDItem(myDialog, 2, &iType, &iHdl, &tBox);
- FrameRect(&tBox);
- InsetRect(&tBox, 4, 2);
- pagesize = tBox.bottom - tBox.top;
- theText = TEStylNew(&tBox, &tBox);
- HLock((Handle) (theText));
-
- GetDItem(myDialog, 7, &iType, &iHdl, &iBox);
- sBar = NewControl(myDialog, &iBox, "\p", false,
- 1, 1, 1, scrollBarProc, 0L);
- ShowControl(sBar);
-
- LoadText(0);
-
- finished = false;
-
- do
- {
- ModalDialog((ModalFilterUPP) MyFilter, &itemHit); /* show dialog/get result */
- switch (itemHit)
- { /* control hit */
- case 1:
- finished = true;
- break;
-
- default:
- break;
- }
- } while (!finished);
-
- HUnlock((Handle) (theText));
- LDispose(theList);
- DisposDialog(myDialog);
- SetPort(savePort);
- TextFont (0);
- TextSize (12);
- }
-
- void InitMacintosh(void)
- {
- MaxApplZone();
-
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- }
-
- void main(void)
- {
- InitMacintosh();
- Help(256, 256);
- }
-